using System;
using THANHTUNGO.Portal.Components.Security;
using THANHTUNGO.Portal.Components.UI;

namespace THANHTUNGO.Portal.Admin.Users
{
    public partial class Users : PortalModuleControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void gvUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
            User u = new User();
            u = User.Load(Convert.ToInt32(gvUsers.SelectedValue));
            if (u != null)
            {
                pnlUserDetail.Visible = true;
                txtName.Text = u.Name;
                txtEmail.Text = u.Email;
                
            }
        }

        protected void btnAssignRoleToUser_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            Role r = new Role();
            if (r.AssignRoleToUser(Convert.ToInt32(cbPortalRoles.SelectedValue), Convert.ToInt32(gvUsers.SelectedValue)) > 0)
            {
                gvRoles.DataBind();
            }
        }

        protected void cbDisplayByDepartment_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtName.Text = txtEmail.Text = string.Empty;
            pnlUserDetail.Visible = false;
        }

        protected void btnChangeDepartment_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            if(User.ChangeDepartment(Convert.ToInt32(gvUsers.SelectedValue), cbDepartment.SelectedValue) > 0)
            {
                gvUsers.DataBind();
            }
        }
    }
}